using System.Text.RegularExpressions;

namespace ArticleManagementSystem.Api.Utils
{
    public class HtmlOrUbb
    {

        public static string HtmlToUBB(dynamic _Html) //html转UBB
        {
            var a = _Html.ToString();

            a = Regex.Replace(a, "<*>", "&gt;");
            a = Regex.Replace(a, "<", "&lt;");
            a = Regex.Replace(a, ":", "&;");
            a = Regex.Replace(a, "'", "@;");
            a = Regex.Replace(a, "\"", "@;@;");
            a = Regex.Replace(a, "&nbsp;", " ");
            a = Regex.Replace(a, "=", "&equs;");
            // a = Regex.Replace(a, "(", "&LParentheses;");
            // a = Regex.Replace(a, ")", "&RParentheses;");
            a = Regex.Replace(a, "{", "&LBraces;");
            a = Regex.Replace(a, "}", "&Rbraces;");


            _Html = a;
            return _Html;
        }
        public static string UBBToHtml(dynamic content)  //ubb转html
        {
            content = content.ToString();
            content = Regex.Replace(content, "&lt;", "<");
            content = Regex.Replace(content, "&gt;", ">");
            content = Regex.Replace(content, "&;", ":");
            content = Regex.Replace(content, "@;", "'");
            content = Regex.Replace(content, "@;@;", "\"");
            content = Regex.Replace(content, " ", "&nbsp;");
            content = Regex.Replace(content, "&equs;", "=");
            content = Regex.Replace(content, "&LParentheses;", "(");
            content = Regex.Replace(content, "&RParentheses;", ")");
            content = Regex.Replace(content, "&LBraces;", "{");
            content = Regex.Replace(content, "&Rbraces;", "}");

            return content;
        }
    }
}

